package org.dfl.core.model.analysis;

import org.dfl.core.model.Edge;
import org.dfl.core.model.TInputEdge;

public class REdge {

	private RPlace place = null;
	private RTransition transition = null;
	private String id;
	private String label;
	
	public static int E_BLANK = 0;
	public static int E_TRUE = 1;
	public static int E_FALSE = -1;
	public static int E_EMPTY = 2;
	public static int E_NOTEMPTY = -2;
	public static int E_NESTED = 3;
	private int flag = E_BLANK;

	public REdge(Edge e) {
		this.id = e.getId();
		this.label = "x";
	}
	
	public REdge(TInputEdge e) {
		this.id = e.getId();
		this.label = (e.getLabel() == "") ? "x" : e.getLabel();
	}

	public String getLabel() {
		return this.label;
	}
	
	public void setFlag(int i) {
		this.flag = i;
	}
	
	public int getFlag() {
		return this.flag;
	}
	
	public boolean isBlank() {
		return (this.flag == E_BLANK);
	}
	
	public boolean isAnnotated() {
		return ((this.flag != E_BLANK) && (this.flag != E_NESTED));
	}
	
	public boolean isNested() {
		return (this.flag == E_NESTED);
	}
	
	public void setId(String s) {
		this.id=s;
	}
	
	public String getId() {
		return this.id;
	}

	public void connectPlaceToTransition(RPlace p, RTransition t) {
		this.place = p;
		this.transition = t;
		p.addOutputEdge(this);
		t.addInputEdge(this);
	}
	
	public void connectTransitionToPlace(RTransition t, RPlace p) {
		this.place = p;
		this.transition = t;
		t.addOutputEdge(this);
		p.addInputEdge(this);
	}
	
	public void disconnect() {
		this.place = null;
		this.transition = null;
	}
	
	public RPlace getPlace() {
		return this.place;
	}
	
	public RTransition getTransition() {
		return this.transition;
	}
}
